using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//
// DotNetNuke?- http://www.dotnetnuke.com
// Copyright (c) 2002-2009
// by DotNetNuke Corporation
//


using DotNetNuke.Common.Utilities;

namespace DotNetNuke.Modules.Html
{

    public partial class WorkflowStateController
    {

        #region "Public Methods"

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddWorkFlow creates a new workflow for the portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="PortalID">The ID of the Portal</param>
        /// <param name="WorkflowName">The Name of the Workflow</param>
        /// <param name="Description">The Description of the Workflow</param>
        /// <param name="IsDeleted">Whether or not the Workflow is Active</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public int AddWorkflow(int PortalID, string WorkflowName, string Description, bool IsDeleted)
        {
            return Convert.ToInt32(DataProvider.Instance().AddWorkflow(PortalID, WorkflowName, Description, IsDeleted));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddWorkFlowState creates a new workflow and state instance
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objWorkflowState">A WorkflowStateInfo object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public int AddWorkflowState(WorkflowStateInfo objWorkflowState)
        {
            int StateID = Convert.ToInt32(DataProvider.Instance().AddWorkflowState(objWorkflowState.WorkflowID, objWorkflowState.StateName, objWorkflowState.Order, objWorkflowState.Notify, objWorkflowState.IsActive));
            DataCache.RemoveCache(string.Format(WORKFLOW_CACHE_KEY, objWorkflowState.WorkflowID.ToString()));
            return StateID;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// CanDeleteWorkFlowState determines whether a workflow state is in use and can be deleted
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="StateID">A WorkflowState ID</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public bool CanDeleteWorkFlowState(int StateID)
        {
            return DataProvider.Instance().CanDeleteWorkFlowState(StateID);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteWorkFlowState deletes a State instance
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="StateID">The StateID</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeleteWorkflowState(int StateID, int WorkflowID)
        {
            DataProvider.Instance().DeleteWorkflowState(StateID);
            DataCache.RemoveCache(string.Format(WORKFLOW_CACHE_KEY, WorkflowID.ToString()));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetWorkFlow retrieves a Workflow object
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="WorkflowID">The ID of the Workflow</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public WorkflowStateInfo GetWorkflow(int WorkflowID)
        {
            return CBO.FillObject(DataProvider.Instance().GetWorkflow(WorkflowID), typeof(WorkflowStateInfo)) as WorkflowStateInfo;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetWorkFlowState retrieves a WorkflowStateInfo object for the Workflow and State
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="StateID">The ID of the State</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public WorkflowStateInfo GetWorkflowState(int StateID)
        {
            return CBO.FillObject(DataProvider.Instance().GetWorkflowState(StateID), typeof(WorkflowStateInfo)) as WorkflowStateInfo;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateWorkFlow updates an existing workflow for the portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="WorkflowID">The ID of the Workflow</param>
        /// <param name="WorkflowName">The Name of the Workflow</param>
        /// <param name="Description">The Description of the Workflow</param>
        /// <param name="IsDeleted">Whether or not the Workflow is Active</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdateWorkflow(int WorkflowID, string WorkflowName, string Description, bool IsDeleted)
        {
            DataProvider.Instance().UpdateWorkflow(WorkflowID, WorkflowName, Description, IsDeleted);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddWorkFlowState creates a new workflow and state instance
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objWorkflowState">A WorkflowStateInfo object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdateWorkflowState(WorkflowStateInfo objWorkflowState)
        {
            DataProvider.Instance().UpdateWorkflowState(objWorkflowState.StateID, objWorkflowState.StateName, objWorkflowState.Order, objWorkflowState.Notify, objWorkflowState.IsActive);
            DataCache.RemoveCache(string.Format(WORKFLOW_CACHE_KEY, objWorkflowState.WorkflowID.ToString()));
        }

        #endregion

    }

}
